package com.whzykj.model;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Record;
import com.whzykj.jfinal.TableBind;

@TableBind(name="store",pk="store_id")
public class Store extends Model<Store>{
	private static final long serialVersionUID = 1L;
	public static final Store me=new Store();
	
	/****
	 * 查询商品库存
	 * @param goods_id
	 * @return
	 */
	public Record getStoreById(String goods_id)
	{
		if(goods_id == null || "".equals(goods_id)) return null;
		String couponQry = " select * from store where goods_id = ? and date(set_date) = curdate() ";
		Record rd = Db.findFirst(couponQry,goods_id);		
		if(rd == null)
		{
			couponQry = " select * from store where goods_id = ? order by set_date desc ";
			rd = Db.findFirst(couponQry,goods_id);	
		}
		return rd;		
	}
	
	/****
	 * 查询商品库存
	 * @param goods_id
	 * @return
	 */
	public Record getStoreById(String goods_id,String curdate)
	{
		if(goods_id == null || "".equals(goods_id)) return null;
		String couponQry = " select * from store where goods_id = ? and set_date=? ";
		Record rd = Db.findFirst(couponQry,goods_id,curdate);		
		return rd;		
	}
}
